/**
 * @Date 2025-09-22 12:49:34
 * @AIDE AIDE+
 */
package com.goldsprite.microhorigame.ecs;

import com.goldsprite.gameframeworks.ecs.component.Component;
import com.goldsprite.gameframeworks.ecs.system.GameSystem;
import com.goldsprite.microhorigame.screens.games.MainGameScreen;
import com.goldsprite.microhorigame.screens.games.MonsterType;
import com.goldsprite.microhorigame.systems.GObjectGenerator;

public class MonsterPortalComponent extends Component {
	//秒, 刷新计时器, 刷新间隔, 开局5秒刷新
	public float fmTicker = 5, fmInterval = 15;
	public MonsterType spawnMonsterType;

	@Override
	public void update(float delta) {
		boolean fightMode = MainGameScreen.options.fightMode;
		if (fightMode) {
			float spawnX = fields.transform.getPosition().x, spawnY = fields.transform.getPosition().y;
			if (GameSystem.getTotalDeltaTime() > fmTicker) {
				fmTicker += fmInterval;
				float ran = 0.3f + (float) Math.random() * 0.7f;
				float x = spawnX + ran * 100 * (float) (Math.random() > 0.5f ? 1 : -1);
				float y = spawnY + 10;

				if (spawnMonsterType == MonsterType.Golem) {
					GObjectGenerator.newGolem(x, y);
				}
				else if (spawnMonsterType == MonsterType.BlackCanine) {
					GObjectGenerator.newBlackCanine(x, y);
				}
				else if (spawnMonsterType == MonsterType.DemonRat) {
					GObjectGenerator.newDemonRat(x, y);
				}
			}
		}
	}
}

